<?php defined('SYSPATH') or die('No direct script access.');
/**
 * Geoip Service
 *
 * $Id$
 *
 * @package    Core
 * @author     Sam Clark
 * @copyright  (c) 2008 Polaris Digital
 * @license    GNU Public Licence v3
 */
abstract class Geoip_Driver {
	
	// Response from Server
	static $response_cache;
		
	// License key for service provider (if required)
	protected $license_key = FALSE;
	
	// Define required value for warning codes
	protected $warning_codes = array();
	
	// Define required value for error codes
	protected $error_codes = array();
	
	// Query the server
	abstract public function query( $ip = FALSE );
	
	/**
	 * Constructor overloading
	 * @return 
	 */
	public function __construct( $config = array() )
	{
		// Setup the license key
		if( array_key_exists( 'key', $config ) )
		{
			$this->license_key = $config['key'];
		}
		
		return TRUE;
	}
	
	/**
	 * Validates an IPv4 IP address format
	 * @return (bool) result
	 * @param $ip Object
	 */
	public function validate_ip( $ip )
	{
		// Return TRUE if the IP address is a valid IPv4 address and not in the private range
		return (bool) filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE);
	}
	
}	// End of GeoIP driver


interface Geoip_Result {

	/**
	 * Returns the GeoIP result as an array
	 * @return result
	 * @param $object Object[optional]
	 */
	public function as_array();
	
	/**
	 * Fetches a value based on the key from the GEOIP result
	 * @return the value associated with the key
	 * @param $key Object[optional]
	 */
	public function __get( $key );
	
	/**
	 * Formats the results for creation of the result object
	 * @return nothing
	 */
	public function format_results();
	
}	// end of Geoip result interface
